The present invention relates to digital data processing systems, and in particular to the initialization of static data in object oriented systems.
Since the dawn of the computer age, computer systems have evolved into extremely sophisticated devices, and computer systems may be found in many different settings. Computer systems typically include a combination of hardware, such as semiconductors and circuit boards, and software, also known as computer programs. As advances in semiconductor processing and computer architecture push the performance of the computer hardware higher, more sophisticated computer software has evolved to take advantage of the higher performance of the hardware, resulting in computer systems today that are much more powerful than just a few years ago.
Computer systems typically include operating system software that controls the basic function of the computer, and one or more software application programs that run under the control of the operating system to perform desired tasks. For example, a typical IBM Personal Computer may run an operating system, and under the control of the operating system, a user may execute an application program, such as a word processor. As the capabilities of computer systems have increased, the application software programs designed for high performance computer systems have become extremely powerful. Additionally, software development costs have continued to rise because more powerful and complex programs take more time, and hence more money, to produce.
One way in which the performance of application software programs has been improved while the associated development costs have been reduced is by using object oriented programming concepts. The goal of using object oriented programming is to create small, reusable sections of program code known as xe2x80x9cobjectsxe2x80x9d that can be quickly and easily combined and re-used to create new programs. This is similar to the idea of using the same set of building blocks again and again to create many different structures. The modular and re-usable aspects of objects will typically speed development of new programs, thereby reducing the costs associated with the development cycle. In addition, by creating and re-using a comprehensive set of well-tested objects, a more stable, uniform, and consistent approach to developing new computer programs can be achieved.
The JAVA(trademark) programming language developed by Sun Microsystems is one modern object oriented programming language that has become very popular in recent years. One key feature of the JAVA language is the platform independence of JAVA source code. I.e., source code complying with the JAVA language semantics may be compiled and executed on any JAVA compliant machine. In fact, source code is typically converted by a JAVA front-end compiler to an intermediate symbolic form referred to as a JAVA bytecode form, which is also platform independent. Programming code in JAVA bytecode form may be run in interpretive mode by any JAVA compliant interpreter, or may be compiled into machine level instructions by a back-end compiler for use in a specific type of computer system environment.
JAVA language semantics support the use of static class variables. A static class variable is a variable which has a value defined for the entire class, as opposed to object variables which may assume different values for each object of the class. Typically, all class variables for a given class are stored together in a common class variable structure.
JAVA language semantics do not dictate the layout or format of any particular class variable structure. For maximum portability and platform independence, JAVA language semantics define static class variables as initialized to zero, except insofar as altered by a static initializer method. The static initializer method ( less than clinit greater than ) for a class is called once during program execution when the class is first loaded. The static initializer method is computer programming code like any other, the purpose of which is merely to initialize the static class variables. As such, it may contain simple assignment statements, but may also contain statements requiring arithmetic calculations, loops, branches, and similar programming constructs. For example, an array may be initialized using loops.
The JAVA language""s static variable initialization semantics differ from those of many other languages, particularly C++. In C++, static variables are typically declared and initialized when the program is compiled. It is therefore not necessary to execute static variable initialization code in C++ to the extent that it is required in the JAVA language. In the JAVA language, the code required to initialize static variables may consume considerable space in the final compiled program module. Moreover, the JAVA language initialization code must execute at run time, which consumes a certain amount of execution time. This need to initialize static variables in the JAVA language at run time puts the performance of compiled JAVA language code at a disadvantage compared with the performance of code compiled in languages such as C++. It would be desirable to reduce the burden of static initialization methods on code size and run-time performance of JAVA language programs (and programs written in languages having similar static initialization semantics), without altering the standard JAVA language definition.
In accordance with the present invention, a compiler for object-oriented programming code in a language which employs run-time static initialization semantics (such as the JAVA language) analyzes the static initialization code to find a subset of initialization statements which must execute under all conditions, creates an image of the static storage in which the variables initialized by statements in the subset are pre-initialized at compile time, and removes statements in the subset from the final compiled code of machine level instructions.
In the preferred embodiment, the compiler is a back-end compiler for the JAVA language, which converts a JAVA bytecode module to a compiled module of machine executable instructions. Static initialization code for each class is contained in a static initializer method for the class. Each static initializer method is decomposed to construct a control flow graph for the method. The control flow graph is analyzed to identify statements in the JAVA bytecode initialization source which must necessarily execute whenever the initialization method is called. The compile-time xe2x80x9cclass variable structurexe2x80x9d (i.e., the image of the static storage) is set everywhere to zero, except for locations affected by these identified statements, which are set at compile time according to the identified statements, i.e., as if the identified statements had executed. The identified statements are then removed from the code being compiled, so that they do not appear in the finished compiled code.
Because the analysis performed by the compiler is finite in scope, and because certain statements might be inappropriate for incorporation into a compile time class variable structure, the compiler of the preferred embodiment does not necessarily guarantee that every statement which must necessarily execute will be identified and incorporated into the compile-time class variable structure. However, in order to maintain compatibility with the JAVA language standard, it should guarantee that every statement which is so incorporated into the compile-time class variable structure must necessarily execute.
As a result of removing statements from the static initialization routines, code size is generally reduced. At the same time, performance at run-time is improved because there are fewer initialization instructions to execute.
The details of the present invention, both as to its structure and operation, can best be understood in reference to the accompanying drawings, in which like reference numerals refer to like parts, and in which: